package com.htc.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.htc.model.ShoppingItem;

public interface ShoppingItemMapper {

	@Insert("insert into shoppingitem(pid,sid,snum) values(#{pid},#{sid},#{snum})")
	public int addShoppingItem(ShoppingItem shoppingItem);

	@Delete("delete from shoppingitem where itemid = #{itemid} ")
	public int deleteShoppingItem(int itemid);
	
	@Select("select *from shoppingitem where sid=#{sid}")
	public List<ShoppingItem> queryShoppingItemListBySid(int sid);
	
	
	@Select("select count(1) from shoppingcar,shoppingitem where shoppingitem.sid=shoppingcar.sid and uid=#{uid} and pid=#{pid}")
	public Integer queryConsumerProductCount(@Param("uid")int uid,@Param("pid")int pid);
	
	@Delete("delete from shoppingitem where pid=#{pid} and sid=(select sid from shoppingcar where uid=#{uid})")
	public void del(@Param("uid")int uid,@Param("pid")int pid);
	
	@Update("update shoppingitem set snum=snum+1 where sid=(select sid from shoppingcar where uid=#{uid}) and pid=#{pid}")
	public void updateCar(@Param("uid")int uid,@Param("pid")int pid);

}
